{include file='public/header' /}
    <style type="text/css">
        .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
        .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
    </style>
</head>
<body style="padding: 10px;">
<div class="header">
    <span>用户管理</span>
    <button class="layui-btn layui-btn-xs" style="float: right;" onclick="add()">添加</button>
    <div></div>
</div>
        <table class="layui-table">
            <thead>
            <tr>
                <th>GID</th>
                <th>角色名称</th>
                <th>权限ID</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="userdata" id='userdata'}
            <tr>
                <td>{$userdata.gid}</td>
                <td>{$userdata.title}</td>
                <td>{$userdata.rights}</td>
                <td>
                    <button class="layui-btn layui-btn-warm layui-btn-xs" onclick="add({$userdata.gid})">编辑</button>
                    <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$userdata.gid})">删除</button>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
<button class="layui-btn " onclick="save()">保存</button>
</body>
</html>
<script type="text/javascript">
    layui.use(['layer'],function(){
        $ = layui.jquery;
        layer = layui.layer;
    });
    //添加
    function add(gid){
        layer.open({
            type: 2,
            title: gid>0?'编辑角色':'添加角色',
            shade: 0.3,
            area: ['580px', '520px'],
            content: '__PUBLIC__/admin/Roles/add?gid='+gid
        });
    }

    // 删除
    function del(id){
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('__PUBLIC__/admin/roles/deletes',{'gid':id},function(res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else{
                    layer.msg(res.msg);
                    setTimeout(function(){window.location.reload();},1000);
                }
            },'json');
        });
    }
</script>